From 773367b44941d9d6eaca3ef2c2e03c0a9fc50758 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Tue, 29 Aug 2006 22:51:06 +0100 Subject: [PATCH] This patch fixed 'xm reboot' to work as you expected with the wait option. This patch adds a restart sequence counter to xenstore. The completion of a VM reboot is detected by observing that its restart sequence counter changes. Signed-off-by: Masaki Kanno --- tools/python/xen/xend/XendDomainInfo.py | 9 ++++ tools/python/xen/xend/server/XMLRPCServer.py | 3 +- tools/python/xen/xm/shutdown.py | 49 +++++++++++++++----- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index ab0554fccd..09029e0535 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -703,6 +703,9 @@ class XendDomainInfo: if security[idx][0] == 'ssidref': to_store['security/ssidref'] = str(security[idx][1]) + if not self.readVm('xend/restart_count'): + to_store['xend/restart_count'] = str(0) + log.debug("Storing VM details: %s", to_store) self.writeVm(to_store) @@ -824,6 +827,9 @@ class XendDomainInfo: def setResume(self, state): self.info['resume'] = state + def getRestartCount(self): + return self.readVm('xend/restart_count') + def refreshShutdown(self, xeninfo = None): # If set at the end of this method, a restart is required, with the # given reason. This restart has to be done out of the scope of @@ -1615,6 +1621,9 @@ class XendDomainInfo: try: new_dom = XendDomain.instance().domain_create(config) new_dom.unpause() + rst_cnt = self.readVm('xend/restart_count') + rst_cnt = int(rst_cnt) + 1 + self.writeVm('xend/restart_count', str(rst_cnt)) new_dom.removeVm(RESTART_IN_PROGRESS) except: if new_dom: diff --git a/tools/python/xen/xend/server/XMLRPCServer.py b/tools/python/xen/xend/server/XMLRPCServer.py index 07495473b3..d075ec7e5e 100644 --- a/tools/python/xen/xend/server/XMLRPCServer.py +++ b/tools/python/xen/xend/server/XMLRPCServer.py @@ -78,7 +78,8 @@ def get_log(): methods = ['device_create', 'device_configure', 'destroyDevice', 'getDeviceSxprs', 'setMemoryTarget', 'setName', 'setVCpuCount', 'shutdown', - 'send_sysrq', 'getVCPUInfo', 'waitForDevices'] + 'send_sysrq', 'getVCPUInfo', 'waitForDevices', + 'getRestartCount'] exclude = ['domain_create', 'domain_restore'] diff --git a/tools/python/xen/xm/shutdown.py b/tools/python/xen/xm/shutdown.py index 7c974f80a9..1fe7fbede5 100644 --- a/tools/python/xen/xm/shutdown.py +++ b/tools/python/xen/xm/shutdown.py @@ -48,21 +48,48 @@ gopts.opt('reboot', short='R', fn=set_true, default=0, use='Shutdown and reboot.') +def wait_reboot(opts, doms, rcs): + while doms: + alive = server.xend.domains(0) + reboot = [] + for d in doms: + if d in alive: + rc = server.xend.domain.getRestartCount(d) + if rc == rcs[d]: continue + reboot.append(d) + else: + opts.info("Domain %s destroyed for failed in rebooting" % d) + doms.remove(d) + for d in reboot: + opts.info("Domain %s rebooted" % d) + doms.remove(d) + time.sleep(1) + opts.info("All domains rebooted") + +def wait_shutdown(opts, doms): + while doms: + alive = server.xend.domains(0) + dead = [] + for d in doms: + if d in alive: continue + dead.append(d) + for d in dead: + opts.info("Domain %s terminated" % d) + doms.remove(d) + time.sleep(1) + opts.info("All domains terminated") + def shutdown(opts, doms, mode, wait): + rcs = {} for d in doms: + rcs[d] = server.xend.domain.getRestartCount(d) server.xend.domain.shutdown(d, mode) + if wait: - while doms: - alive = server.xend.domains(0) - dead = [] - for d in doms: - if d in alive: continue - dead.append(d) - for d in dead: - opts.info("Domain %s terminated" % d) - doms.remove(d) - time.sleep(1) - opts.info("All domains terminated") + if mode == 'reboot': + wait_reboot(opts, doms, rcs) + else: + wait_shutdown(opts, doms) def shutdown_mode(opts): if opts.vals.halt and opts.vals.reboot: -- 2.30.2